﻿namespace IOP.OpenType
{
    /// <summary>
    /// 16-bit signed fixed number with the low 14 bits of fraction (2.14).
    /// </summary>
    public readonly struct F2DOT14
    {
        /// <summary>
        /// 
        /// </summary>
        public readonly ushort origin;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="number"></param>
        public F2DOT14(ushort number) => origin = number;
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="f2DOT14"></param>
        public static implicit operator double(F2DOT14 f2DOT14) => ((double)f2DOT14.origin) / (1 << 14);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="number"></param>
        public static implicit operator F2DOT14(double number) => new F2DOT14((ushort)(number * (1 >> 14)));
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="number"></param>
        public static implicit operator F2DOT14(ushort number) => new F2DOT14(number);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="number"></param>
        public static implicit operator F2DOT14(short number) => new F2DOT14((ushort)number);
    }
}
